package com.web;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import com.domain.User;
import com.service.Impl.UsersServiceImpl;
import com.service.UsersService;

@WebServlet("/checkedServlet")
public class checkedServlet extends HttpServlet{
	@Override
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
        //获取域中登录用户名
        HttpSession session = request.getSession();
        String name = (String) session.getAttribute("username");
        //获取登录用户名信息
        UsersService usersService = new UsersServiceImpl();
        User user = usersService.findByName(name);
        //得到ID可以根据用户id修改密码
        int id = user.getId();
        //获取输入框的密码数据
        String username = request.getParameter("username");
        String password = request.getParameter("password");
        System.out.println(password);
        if(password.equals(username)) {
            session.setAttribute("mess", "密码不能为空~~");
            response.sendRedirect("/woniusales/page/vipPage.jsp");
            return;
        }
        System.out.println("确认密码:"+password);

        //传递下一层
        usersService.updatePassword(id, password);
        //重定向到当前页面
        session.setAttribute("mess", "修改密码成功~~");
        response.sendRedirect("/woniusales/page/vipPage.jsp");

    }
	@Override
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		this.doGet(request, response);
	}
}
